// 
// Decompiled by Procyon v0.5.36
// 

package com.orange.boot.dev1.controller;

import org.springframework.web.bind.annotation.PostMapping;
import io.swagger.annotations.ApiOperation;
import java.util.Iterator;
import com.orange.boot.dev1.entity.NewsDetails;
import org.springframework.web.bind.annotation.RequestBody;
import com.orange.boot.dev1.entity.DetailUrl;
import org.springframework.web.bind.annotation.GetMapping;
import com.orange.boot.dev1.entity.NewsOverview;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import com.orange.boot.dev1.entity.TechnologyItem;
import java.util.List;
import com.orange.boot.utils.R;
import com.orange.boot.dev1.service.NewsDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import com.orange.boot.dev1.service.NewsOverviewService;
import org.springframework.web.bind.annotation.CrossOrigin;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/dev1/technology"})
@Api(
        tags = {"种植技术"}
)
@CrossOrigin
public class TechnologyController {
    @Autowired
    private NewsOverviewService overviewService;
    @Autowired
    private NewsDetailsService detailsService;

    public TechnologyController() {
    }

    @GetMapping({"list"})
    public R list() {
        List<NewsOverview> list = this.overviewService.list();
        List<TechnologyItem> items = (List)list.stream().map((item) -> {
            TechnologyItem technology = new TechnologyItem();
            technology.setTitle(item.getTitle());
            technology.setPicUrl(item.getImage());
            technology.setDetailUrl(item.getDetailUrl());
            return technology;
        }).collect(Collectors.toList());
        return R.ok().data("items", items);
    }

    @ApiOperation("根据详情页的url返回详情页信息")
    @PostMapping({"detail"})
    public R detail(@RequestBody DetailUrl detailUrl) {
        String url = detailUrl.getDetailUrl();
        List<NewsDetails> list = this.detailsService.list();
        NewsDetails target = null;
        Iterator var5 = list.iterator();

        while(var5.hasNext()) {
            NewsDetails newsDetails = (NewsDetails)var5.next();
            if (newsDetails.getUrl().equals(url)) {
                target = newsDetails;
                break;
            }
        }

        return target == null ? R.error("没有对应网址的爬虫信息") : R.ok().data("detailHtml", target.getText());
    }
}